<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			function show(){
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText; 
						var arr=JSON.parse(r)
						var str=`
						<table border="1" width="700px">
							<tr>
								<th>用户名称</th>
								<th>用户邮箱</th>
								<th>用户电话</th>
								<th>真实姓名</th>
								<th>用户性别</th>
								<th>操作</th>
							</tr>
						`
						for(i=0;i<arr.length;i++){
							var sex="保密"
							if(arr[i].gender==1){
								sex="男"
							}else if(arr[i].gender==0){
								sex="女"
							}else{
								sex="保密"
							}
							str+=`<tr align="center">
											<td>${arr[i].uname}</td>
											<td>${arr[i].email}</td>
											<td>${arr[i].phone}</td>
											<td>${arr[i].user_name}</td>
											<td>${sex}</td>
											<td>
												<a href="javascript:del(${arr[i].uid})">删除</a>
												<a href="4_search.html?uid=${arr[i].uid}">修改</a>
											</td>
										</tr>`
						}
						str+=`</table>`
						d1.innerHTML=str;
					}
				}
				xhr.open("get",`/ajax/v1/list`,true)
				xhr.send();
			}
			function del(_uid){
				//var _uid=uid.value;
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText;
						if(r==1){
							alert("删除成功");
							//location.href="2_list.html"
							show();
						}else{
							alert("删除失败")
						}
					}
				}
			xhr.open("delete",`/ajax/v1/del/${_uid}`,true)
			xhr.send();
			}
		</script>
	</head>
	<body onload="show()">
		<div id="d1">
			
			
		</div>
	</body>
</html>
